/*
 * @Descripttion:
 * @version:
 * @Author: kl2018
 * @Date: 2020-08-04 10:54:04
 * @LastEditors: kl2018
 * @LastEditTime: 2020-09-24 17:02:04
 */
import React, { Component } from 'react';
import { inject, observer } from 'mobx-react';
// import ReceiveDoc from './ReceiveDoc';
import BaseTableComp from './common/BaseTableComp';
import ReceiveRegistDialog from './ReceiveDoc/ReceiveRegistDialog';
import { affirmDeleted } from '../util/affirmDeleted';
// import { Button } from "antd";
import { WeaLocaleProvider } from 'ecCom';

const { getLabel } = WeaLocaleProvider;

@inject('registDocStore')
@observer
class ReceiveDocRegistComp extends Component {

  componentDidMount() {
    const { registDocStore } = this.props;
    const { setMobxState } = registDocStore;
    const getDatas = this.baseTableComp && this.baseTableComp.wrappedInstance.getTableDatasByDirect;
    setMobxState({ getDatas });
  }

  componentWillUnmount () { 
    const { registDocStore } = this.props;
    registDocStore.setMobxState({ getDatas: () => { } });
  }

  render() {
    return (
      // <ReceiveDoc ecId={`${this && this.props && this.props.ecId || ''}_ReceiveDoc@adwma1`} menuType={'receiptRegistration'} {...this.props} />
      <BaseTableComp
        ecId={`${this && this.props && this.props.ecId || ''}_BaseTableComp@6e6b4c`}
        getColumns={this.getColumn}
        topTitle={getLabel('33788', '收文登记')}
        searchType={['base', 'advanced']}
        topBtns={this.getTopBtns()}
        tabKey="customTabId"
        baseSearchName={'title'}
        searchFormUrl="/api/offical/receiveDoc/condition"
        tableUrl="/api/offical/receiveDoc/getList"
        ref={refs => this.baseTableComp = refs}
        showCustomCol={true}
        showExportTable={true}
        moreTimeGetCondition={false}
        onOperatesClick={this.onOperatesClick}
        tableParams={{ menuType: 'receiptRegistration' }}
        getOtherDom={this.getOtherDom}
        {...this.props}
      />
    );
  }

  getTopBtns=()=> {
    const { registDocStore } = this.props;
    const { showRegistDialog, delList } = registDocStore;
    const buttons = [
      {
        isDropDown: false,
        icon: <i className="icon-coms-shouxie" />, // 右键菜单选项的图标
        title: getLabel('510164', '来文登记'),
        onClick: showRegistDialog,
        needCheck: false,
      },
      {
        isDropDown: false,
        icon: <i className="icon-coms-Delete" />, // 右键菜单选项的图标
        title: getLabel('32136', '批量删除'),
        onClick: keys => affirmDeleted(() => delList(keys.join(','))),
        needCheck: true,
      },
    ];
    return buttons;
  }

  onOperatesClick = (record, index) => {
    const { registDocStore } = this.props;
    const { delList, getRegistrationFormData } = registDocStore;

    // 收文登记
    registDocStore.type = record.receive_doc_type;
    // 收文登记
    if (index == '0') {
      registDocStore.selectRowId = [record.id];
      registDocStore.document_identifier = record.document_identifier;
      getRegistrationFormData();
    } else if (index == '1') {
      registDocStore.isReceivecheck = true;
      registDocStore.selectRowId = [record.id];
      getRegistrationFormData();
    } else if (index == '2') {
      // 删除
      const params = { content: getLabel('15097', '确定要删除吗？') };
      affirmDeleted(() => delList(record.id), params);
    }
  }

  getOtherDom = () => <ReceiveRegistDialog ecId={`${this && this.props && this.props.ecId || ''}_ReceiveRegistDialog@3odgzu`} />

  getColumn = columns => columns.map((col) => {
    if (col.dataIndex == 'document_title') {
      return {
        ...col,
        title: col.title,
        render: (text, record) => {
          let flag = '1';
          if (record.registration_processing == '') {
            flag = '0';
          }
          return (
            <a title={record.document_title} onClick={() => this.onOperatesClick(record, flag)}>{record.document_title}</a>
          );
        },
      };
    }
    return col;
  })

  openWorkflow(requestid) {
    window.open(`/workflow/request/ViewRequestForwardSPA.jsp?requestid=${requestid}`);
  }
}

export default ReceiveDocRegistComp;
